package com.spzx.order.receiver;

import com.spzx.common.rabbit.constant.MqConst;
import com.spzx.order.service.IOrderInfoService;
import jakarta.annotation.Resource;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;
import com.rabbitmq.client.Channel;



@Slf4j
@Component
public class OrderReceiver {
    @Resource
    IOrderInfoService orderInfoService;
    @SneakyThrows
    @RabbitListener(queues = MqConst.QUEUE_CANCEL_ORDER)
    public void  processCloseOrder(String orderId, Message message, Channel channel){
        byte[] body = message.getBody();
        String msg = new String(body);
        System.out.println(MqConst.QUEUE_CANCEL_ORDER +"队列监听："+msg+" "+orderId);
        System.out.println("延迟关闭订单："+orderId);
        orderInfoService.processCloseOrder(orderId);
        channel.basicAck(message.getMessageProperties().getDeliveryTag(),false);// 手动应答
    }
}
